var api = require('./api.js');
var app = getApp();
/**
 * 网络请求方法
 * @param url {string} 请求url
 * @param data {object} 参数
 * @param successCallback {function} 成功回调函数
 * @param errorCallback {function} 失败回调函数
 * @param completeCallback {function} 完成回调函数
 * @returns {void} 返回回调函数的结果
 */

function requestData(url, data0, successCallback, errorCallback) {
    wx.request({
        url: url,
        method: 'POST',
        data: data0,
        success: function (res) {
            successCallback(res);
        },
        error: function (res) {
            errorCallback(res);
        },
    });
}
function requestDataPic(url, data0, imageList, successCallback, errorCallback) {
    wx.uploadFile({
        url: url,
        filePath: imageList,
        name: 'file',
        formData: data0,
        success: function (res) {
            successCallback(res);
        },
        error: function (res) {
            errorCallback(res);
        },
    })
}
// 授权登录
function login(data0, successCallback, errorCallback) {
    requestData(api.login(), data0, successCallback, errorCallback);
}
// 获取Banner
function getBanner(data0, successCallback, errorCallback) {
    requestData(api.getBanner(), data0, successCallback, errorCallback);
}
// 存储用户信息
function checkLogin(data, successCallback, errorCallback) {
    requestData(api.checkLogin(), data, successCallback, errorCallback);
}
// 个人中心
function getUser(data, successCallback, errorCallback) {
    requestData(api.getUser(), data, successCallback, errorCallback);
}
// 分类列表信息
function bindPhone(data, successCallback, errorCallback) {
  requestData(api.bindPhone(), data, successCallback, errorCallback);
}
function getMapList(data, successCallback, errorCallback) {
  requestData(api.getMapList(), data, successCallback, errorCallback);
}
function getBookStore(data, successCallback, errorCallback) {
  requestData(api.getBookStore(), data, successCallback, errorCallback);
}
function rechargeMoney(data, successCallback, errorCallback) {
  requestData(api.rechargeMoney(), data, successCallback, errorCallback);
}
function rechargePay(data, successCallback, errorCallback) {
  requestData(api.rechargePay(), data, successCallback, errorCallback);
}

function addDeposit(data, successCallback, errorCallback) {
  requestData(api.addDeposit(), data, successCallback, errorCallback);
}
function addDepositMoney(data, successCallback, errorCallback) {
  requestData(api.addDepositMoney(), data, successCallback, errorCallback);
}

function addBaoxiu(data, successCallback, errorCallback) {
  requestData(api.addBaoxiu(), data, successCallback, errorCallback);
}
function addPic(data, imageList, successCallback, errorCallback) {
  requestDataPic(api.addPic(), data, imageList, successCallback, errorCallback);
}

function rerundMoney(data, successCallback, errorCallback) {
  requestData(api.rerundMoney(), data, successCallback, errorCallback);
}
function getIsDeposit(data, successCallback, errorCallback) {
  requestData(api.getIsDeposit(), data, successCallback, errorCallback);
}
function getRecord(data, successCallback, errorCallback) {
  requestData(api.getRecord(), data, successCallback, errorCallback);
}
function getTotalMoney(data, successCallback, errorCallback) {
  requestData(api.getTotalMoney(), data, successCallback, errorCallback);
}
function isBindPhone(data, successCallback, errorCallback) {
  requestData(api.isBindPhone(), data, successCallback, errorCallback);
}
function getOrderList(data, successCallback, errorCallback) {
  requestData(api.getOrderList(), data, successCallback, errorCallback);
}
function getOrderDetail(data, successCallback, errorCallback) {
  requestData(api.getOrderDetail(), data, successCallback, errorCallback);
}
function reduceBalance(data, successCallback, errorCallback) {
  requestData(api.reduceBalance(), data, successCallback, errorCallback);
}
function openDoor(data, successCallback, errorCallback) {
  requestData(api.openDoor(), data, successCallback, errorCallback);
}
function getIsOpenDoor(data, successCallback, errorCallback) {
  requestData(api.getIsOpenDoor(), data, successCallback, errorCallback);
}
function getNewOrderList(data, successCallback, errorCallback) {
  requestData(api.getNewOrderList(), data, successCallback, errorCallback);
}
function getUid(data, successCallback, errorCallback) {
  requestData(api.getUid(), data, successCallback, errorCallback);
}

function reduceManyBalance(data, successCallback, errorCallback) {
  requestData(api.reduceManyBalance(), data, successCallback, errorCallback);
}
function getLostBook(data, successCallback, errorCallback) {
  requestData(api.getLostBook(), data, successCallback, errorCallback);
}
function getYouHuiList(data, successCallback, errorCallback) {
  requestData(api.getYouHuiList(), data, successCallback, errorCallback);
}
function addUserDeposit(data, successCallback, errorCallback) {
  requestData(api.addUserDeposit(), data, successCallback, errorCallback);
}
function getQuestionList(data, successCallback, errorCallback) {
  requestData(api.getQuestionList(), data, successCallback, errorCallback);
}
function getNewUser(data, successCallback, errorCallback) {
  requestData(api.getNewUser(), data, successCallback, errorCallback);
}
function getTypeBook(data, successCallback, errorCallback) {
  requestData(api.getTypeBook(), data, successCallback, errorCallback);
}


module.exports = {
    login: login,
    getBanner: getBanner,
    checkLogin: checkLogin,
    getUser: getUser,
    bindPhone: bindPhone,
    getMapList: getMapList,
    getBookStore: getBookStore,
    rechargeMoney: rechargeMoney,
    rechargePay:rechargePay,
    addDeposit: addDeposit,
    addDepositMoney: addDepositMoney,
    addBaoxiu: addBaoxiu,
    addPic:addPic,
    rerundMoney:rerundMoney,
    getIsDeposit: getIsDeposit,
    getRecord: getRecord,
    getTotalMoney: getTotalMoney,
    isBindPhone: isBindPhone,
    getOrderList: getOrderList,
    getOrderDetail: getOrderDetail,
    reduceBalance: reduceBalance,
    openDoor: openDoor,
    getIsOpenDoor: getIsOpenDoor,
    getNewOrderList: getNewOrderList,
    getUid: getUid,
    reduceManyBalance: reduceManyBalance,
    getLostBook: getLostBook,
    getYouHuiList: getYouHuiList,
    addUserDeposit: addUserDeposit,
    getQuestionList: getQuestionList,
    getNewUser: getNewUser,
    getTypeBook: getTypeBook
};